package org.cangku.controller;

import org.cangku.dao.RolePermissionDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/rolepermission")
public class RolePermissionController {
    @Autowired
    private RolePermissionDao rolePermissionDao;

    @RequestMapping("/updaterpm")
    @ResponseBody
    public Map<String,Object> updateRolePermission(int roleid,String pmids){
        Map<String,Object> map = new HashMap<String, Object>();
        rolePermissionDao.deleteAllByRoleid(roleid);

        String[] pmid = pmids.split("-");
        for (int i = 0;i<pmid.length;i++){
            rolePermissionDao.insertRolePermission(roleid,Integer.parseInt(pmid[i]));
        }
        map.put("msg","1");
        return  map;
    }
}
